package com.qj.yantaishan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.IService;
import com.qj.yantaishan.domain.Return;
import com.qj.yantaishan.vo.OrderReturnVo;
import com.qj.yantaishan.vo.ReturnOrderVo;
import com.qj.yantaishan.vo.ReturnProductVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 【请填写功能名称】Mapper接口
 *
 * @author qihe
 * @date 2022-07-22
 */
@Mapper
public interface ReturnMapper extends BaseMapper<Return> {
    /**
     * 查询退款订单信息
     *
     * @param orderId
     * @return
     */
    @Select("select sp.image product_image,sp.name product_name, so.postage,sop.supply_price,sop.pro_num,sop.pro_price," +
            "(sop.pro_num*sop.pro_price) sub_total from  shanglala_order  so inner join shanglala_order_product sop on" +
            " so.order_id = sop.order_id inner join shanglala_product sp on sop.product_id = sp.product_id  inner join shanglala_return sr on sr.order_id = so.order_id where sr.id = #{returnId}")
    List<ReturnOrderVo> selectReturnOrderList(@Param("returnId") Integer returnId);

    @Select("select sp.image product_iamge,sp.name product_name ,sr.type,sr.status,srp.pro_num,sr.dateline ,sr.phone,su.nickname from shanglala_return sr inner join shanglala_return_product srp on  sr.order_id = srp.order_id  inner join shanglala_product sp\n" +
            "on srp.product_id = sp.product_id  inner join shanglala_user su on sr.uid =su.uid    where sr.id = #{returnId}")
    List<ReturnProductVo> selectReturnProductList(@Param("returnId") Integer returnId);

    @Select("<script>" +
            "  select sr.id,sr.return_no,\n" +
            "        sr.dateline,\n" +
            "        sr.order_id,\n" +
            "        sr.order_no,\n" +
            "        sr.type,\n" +
            "        sr.phone,\n" +
            "        so.third_id,\n" +
            "        sr.status,\n" +
            "        sp.name product_name,\n" +
            "        sp.image product_image,\n" +
            "        srp.pro_num,\n" +
            "        su.nickname user_name\n" +
            "        from shanglala_return sr\n" +
            "        inner join shanglala_order so on sr.order_id = so.order_id\n" +
            "        inner join shanglala_return_product srp on so.order_id = srp.order_id\n" +
            "        left join shanglala_product sp on srp.product_id = sp.product_id\n" +
            "        inner join shanglala_user su on sr.uid = su.uid\n" +
            "        <where>\n" +
            "             \n" +
            "            <if test=\"returnNo!=0\">\n" +
            "                and sr.return_no like '%'#{returnNo}'%'\n" +
            "            </if>\n" +
            "            <if test=\"thirdId!=0\">\n" +
            "                and so.third_id like '%'#{thirdId}'%'\n" +
            "            </if>\n" +
            "            <if test=\"status!=0\">\n" +
            "                and so.status=#{status}\n" +
            "            </if>\n" +
            "        </where>\n" +
            "        limit #{current},#{pageSize}" +
            "" +
            "" +
            "</script>")
    List<OrderReturnVo> selectOrderReturnList(@Param("current") Integer current, @Param("pageSize") Integer pageSize, @Param("returnNo") String returnNo, @Param("thirdId") String thirdId, @Param("status") Integer status);

    @Select("select count(*) from shanglala_return")
    int selectTotal();

    @Select("select distinct   sp.image product_image,sp.name product_name, srp.pro_num ,sr.type,sr.status return_status, sr.dateline,su.nickname,su.phone from shanglala_return sr left join  shanglala_return_product srp on sr.order_id = srp.order_id inner join shanglala_product sp on srp.product_id = sp.product_id  inner join shanglala_user su on  sr.uid=su.uid where  sr.order_id = #{orderId} GROUP BY sp.product_id ")
    List<Map<String,Object>> selectReturnProduct(@Param("orderId") Integer orderId);
}
